#include "VSUserSampler.h"
#include "VSResourceManager.h"
#include "VSGraphicInclude.h"
#include "VSStream.h"
using namespace VSEngine2;
IMPLEMENT_RTTI(VSUserSampler,VSObject)
BEGIN_ADD_PROPERTY(VSUserSampler,VSObject)
REGISTER_PROPERTY(m_uiTexType,TexType,VSProperty::F_SAVE_LOAD_CLONE)
REGISTER_PROPERTY(m_Name,Name,VSProperty::F_SAVE_LOAD_CLONE)
REGISTER_PROPERTY(m_pTexture,Texture,VSProperty::F_SAVE_LOAD_CLONE)
REGISTER_PROPERTY(m_uiRegisterIndex,RegisterIndex,VSProperty::F_SAVE_LOAD_CLONE)
END_ADD_PROPERTY
IMPLEMENT_INITIAL_BEGIN(VSUserSampler)
IMPLEMENT_INITIAL_END
VSUserSampler::VSUserSampler()
{
	m_uiTexType = VSTexture::TT_2D;
	m_pTexture = NULL;
}
VSUserSampler::~VSUserSampler()
{
	m_pTexture = NULL;

}
VSUserSampler::VSUserSampler(const VSUsedName & Name,unsigned int uiTexType,unsigned int uiRegisterIndex)
{
	m_Name = Name;
	m_uiTexType = uiTexType;
	m_uiRegisterIndex = uiRegisterIndex;
}
unsigned int VSUserSampler::DiskUse()const
{
	unsigned int Used = VSObject::DiskUse();
	Used += sizeof(unsigned int);
	Used += m_Name.DiskUse();
	return Used;
}

bool VSUserSampler::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!VSObject::Save(rStream,iSaveUse))
		return 0;


	if(!rStream.Write(&m_uiTexType,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);


	if (!m_Name.Save(rStream,iSaveUse))
	{
		return 0;
	}

	return 1;
}
bool VSUserSampler::Load(VSStream & rStream,unsigned int &iSaveUse)
{
	if(!VSObject::Load(rStream,iSaveUse))
		return 0;

	if(!rStream.Read(&m_uiTexType,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if (!m_Name.Load(rStream,iSaveUse))
	{
		return 0;
	}

	return 1;
}

bool VSUserSampler::Clone(const VSObject *pObject,unsigned int uiType)
{
	const VSUserSampler* Temp = DynamicCast<VSUserSampler>(pObject); 
	if(!Temp)
		return 0;

	if(VSObject::Clone(pObject,uiType))
	{

		m_uiTexType = Temp->m_uiTexType;
		m_pTexture = Temp->m_pTexture;
		m_Name = Temp->m_Name;
		return 1;	
	}
	else
		return 0;
}